package tq.com.tqstudent.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.bumptech.glide.Glide;

import java.util.ArrayList;

import tq.com.tqstudent.App;
import tq.com.tqstudent.R;

/**
 * @Author rames
 * @date 2019/4/3 13:42
 */
public class ShareItemAdapter extends BaseAdapter {
    private Context context;
    private ArrayList<String> list;

    public ShareItemAdapter(Context context){
        this.context = context;
    }

    public void setData(ArrayList<String> list){
        this.list = list;
    }

    @Override
    public int getCount() {
        return null == list ? 0 : list.size();
    }

    @Override
    public Object getItem(int i) {
        return list.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        Holder holder;
        if(null == view){
            holder = new Holder();
            view = LayoutInflater.from(context).inflate(R.layout.item_item_share_list, null);
            holder.image = view.findViewById(R.id.image);
            view.setTag(holder);
        } else {
            holder = (Holder) view.getTag();
        }

        Glide.with(context).load(list.get(i)).into(holder.image);
        return view;
    }

    class Holder{
        ImageView image;
    }
}
